import os,hashlib,sys
from binascii import hexlify as _hexlify, unhexlify
from src.cmdcolor import *
from src.config import *
from src.common import *
from src import *

printDarkYellow("\n 温馨提示: 该脚本所生成的boot.dat和license.dat目前暂时不支持硬破Mariko机型,所用的boot需为3.1版,向下兼容,老版本sxos不做适配 \n")

init()

f = open(bootori, "rb")
bootin = f.read()
f.close()

check_boot_v(bootin)

#--------------用户输入判断---------
while (1):
 sdfile = input('\n 是否使用Emunand的boot.dat(SD Files): 是 (y): 否 (n): ') or "y"
 printDarkGreen(' '+sdfile+'\n')
 if sdfile == "y" or sdfile == "n" :
  break

while (1):
 autoboot = input('\n 是否设置开机跳过boot: 是 (y): 否 (n): ') or "n"
 printDarkGreen(' '+autoboot+'\n')
 if autoboot == "y" or autoboot == "n" :
  break

print("\n 请选择制作的SXOS主题: ")
printDarkSkyBlue("""
  1.原版SXOS主题
  2.Atmosphere theme
  3.Dragon Ball theme
  4.Luigi Mansion 1 theme
  5.Luigi Mansion 2 theme
  6.Sharigan theme
  7.SX Core theme
  8.SX Lite theme
  9.SX OS theme
  10.Wood SX theme
  11.自定义主题(请将自定义主题文件放置themes文件夹下)
""")
while (1):
 themesId = input('\n 请选择安装的主题编号(默认: 1): ') or "1"
 printDarkGreen(' '+themesId+'\n')
 if int(themesId) >= 1 and int(themesId) <= 11 :
  break

isthemes = get_theme_status(themesId)

while (1):
 icone_holder = input('\n 是否新增一个引导: 是 (y): 否 (n): ') or "y"
 printDarkGreen(' '+icone_holder+'\n')
 if icone_holder == "y" or icone_holder == "n" :
  break

if os.path.isfile('out/holder.bin') and icone_holder == 'y':
  payload = input('\n 请设置新引导按钮的引导文件路径(默认: payload.bin):') or "payload.bin"
  printDarkGreen(' '+payload+'\n')
  name1 = input('\n 设置第一个引导按钮的名字(默认: Hekate):') or "Hekate"
  printDarkGreen(' '+name1+'\n')
  name2 = input('\n 请设置第二个按钮的名字(默认: Boot custorm FW):') or "Boot custorm FW"
  printDarkGreen(' '+name2+'\n')
  name3 = input('\n 请设置第三个按钮的名字(默认: Boot original FW):') or "Boot original FW"
  printDarkGreen(' '+name3+'\n')
elif not os.path.isfile('out/holder.bin') and icone_holder == 'y':
  printDarkRed('未检测到out目录下的holder.bin文件，请确认themes下是否有holder.bmp文件并且运行了GFX_sxos.exe \n')
  os.system('pause')
  sys.exit()

while (1):
 islicense = input('\n 是否生成免费的license证书: 是 (y): 否 (n): ') or "y"
 printDarkGreen(' '+islicense+'\n')
 if islicense == "y" or islicense == "n" :
  break

if islicense == 'y':
  licenseStatus = input('\n 自定义License Status内容: ') or "Free License"
  printDarkGreen(' '+licenseStatus+'\n')
#--------------用户输入判断End---------

#--------------写入boot.dat End---------
bootout = open(bootbin, "wb")
bootout.write(bootin)
#--------------引入主题模块---------
assets_tmp = open(assets, "wb")
assets_tmp.write(aes_ctr_dec(bootin[0x600DE0:0x600DE0+0x4DC400], assets_key, assets_ctr))
if os.path.isfile('out/menu_bg.bin') and isthemes:
 tmp = open('out/menu_bg.bin', "rb")
 GFX = tmp.read()
 tmp.close()
 assets_tmp.seek(0x400)
 assets_tmp.write(GFX)
if os.path.isfile('out/options.bin') and isthemes:
 tmp = open('out/options.bin', "rb")
 GFX = tmp.read()
 tmp.close()
 assets_tmp.seek(0x400400)
 assets_tmp.write(GFX)
if os.path.isfile('out/bootcfw.bin') and isthemes:
 tmp = open('out/bootcfw.bin', "rb")
 GFX = tmp.read()
 tmp.close()
 assets_tmp.seek(0x440400)
 assets_tmp.write(GFX)
if os.path.isfile('out/bootofw.bin') and isthemes:
 tmp = open('out/bootofw.bin', "rb")
 GFX = tmp.read()
 tmp.close()
 assets_tmp.seek(0x480400)
 assets_tmp.write(GFX)
if os.path.isfile('out/launch.bin') and isthemes:
 tmp = open('out/launch.bin', "rb")
 GFX = tmp.read()
 tmp.close()
 assets_tmp.seek(0x4C0400)
 assets_tmp.write(GFX)
if os.path.isfile('out/poweroff.bin') and isthemes:
 tmp = open('out/poweroff.bin', "rb")
 GFX = tmp.read()
 tmp.close()
 assets_tmp.seek(0x4C4400)
 assets_tmp.write(GFX)
if os.path.isfile('out/repair.bin') and isthemes:
 tmp = open('out/repair.bin', "rb")
 GFX = tmp.read()
 tmp.close()
 assets_tmp.seek(0x4C8400)
 assets_tmp.write(GFX)
if os.path.isfile('out/autorcm.bin') and isthemes:
 tmp = open('out/autorcm.bin', "rb")
 GFX = tmp.read()
 tmp.close()
 assets_tmp.seek(0x4CC400)
 assets_tmp.write(GFX)
if os.path.isfile('out/emunand.bin') and isthemes:
 tmp = open('out/emunand.bin', "rb")
 GFX = tmp.read()
 tmp.close()
 assets_tmp.seek(0x4D0400)
 assets_tmp.write(GFX)
if os.path.isfile('out/nand.bin') and isthemes:
 tmp = open('out/nand.bin', "rb")
 GFX = tmp.read()
 tmp.close()
 assets_tmp.seek(0x4D4400)
 assets_tmp.write(GFX)
if os.path.isfile('out/core.bin') and isthemes:
 tmp = open('out/core.bin', "rb")
 GFX = tmp.read()
 tmp.close()
 assets_tmp.seek(0x4D8400)
 assets_tmp.write(GFX)
if os.path.isfile('out/holder.bin') and icone_holder == "y":
 tmp = open('out/holder.bin', "rb")
 GFX = tmp.read()
 tmp.close()
 assets_tmp.seek(0x3C0400)
 assets_tmp.write(GFX)
assets_tmp.seek(0x0)
with open(assets, 'rb') as f:
 bytes = f.read()
 sha256_assets = hashlib.sha256(bytes).hexdigest()
bootout.seek(0x600DE0)
bootout.write(aes_ctr_dec(bytes, assets_key, assets_ctr))
assets_tmp.close()
os.remove(assets)
 #--------------引入主题模块End---------

#bootloader_88000000.bin
BL = open(bootloader, "wb")
BL.write(aes_ctr_dec(bootin[0x5B6DE0:0x5B6DE0+0x4A000], bootloader_key, bootloader_ctr))
#supprime le chiffrement de la memoire
BL.seek(0x4E0)
BL.write(RET0)

#no boot auto
if autoboot == "y":
  boot_auto = unhexlify("80000034")
  BL.seek(0x682C)
  BL.write(boot_auto)

#--------------设置菜单四个按钮---------
if icone_holder == 'y':
#Boot Director
 BL.seek(0x49F20)
 BL.write(payload.encode())
#nom holder boutton
 BL.seek(0x49f80)
 BL.write(name1.encode()+END)
#name button (Boot custom CFW) 
 BL.seek(0x3F550)
 BL.write(name2.encode()+END)
#name button (Boot custom OFW) 
 BL.seek(0x3F567)
 BL.write(name3.encode()+END)
 
#buton emunand
 buton_emu = unhexlify("01028052")#10
 BL.seek(0x6d08)#left right
 BL.write(buton_emu)
 BL.seek(0x6d14)#up down
 BL.write(buton_emu)
#rediretion retour boot atmo
 menu_d = unhexlify("01B52154")
 BL.seek(0x68d0)
 BL.write(menu_d)
#redirection menu lancement
 menu = unhexlify("1F3400714148DE541A00009440F2FE17")
 BL.seek(0x49f70)
 BL.write(menu)
#menu lancement fonction boot.bin comparaison
 menu = unhexlify("1F3400714148DE541A00009440F2FE17")
 BL.seek(0x49f70)
 BL.write(menu)
#fonction de lancement du boot.bin
 payload_F = unhexlify("0000009000803C915DFDFE97")
 BL.seek(0x49FE0)
 BL.write(payload_F)
#nom d'icone 
 icone = unhexlify("484F4C444552")
 BL.seek(0x49f90)
 BL.write(icone)
#taille pour 4 icone
 payload_L_icone = unhexlify("01A08052")
 BL.seek(0x6c30)
 BL.write(payload_L_icone)
#centrer les icones
 centre_icone = unhexlify("010A8052")
 BL.seek(0x6c04)
 BL.write(centre_icone)
#redirection d'ajout icone
 payload_D_icone = unhexlify("CD0C0114")
 BL.seek(0x6c6c)
 BL.write(payload_D_icone)
#ajout d'icone
 payload_icone = unhexlify("E00313AA030000900200009063003C9142003E910100009021403E917BF2FE97E00313AA2BF3FE17")
 BL.seek(0x49FA0)
 BL.write(payload_icone)
#retour boot atmo
 menu_r_boot = unhexlify("801C00B0A101805201600AB920008052C0035FD6")
 BL.seek(0x49f00)
 BL.write(menu_r_boot)

BL.seek(0x47E40)
BL.write(unhexlify(sha256_assets))
BL.seek(0x0)
with open(bootloader, 'rb') as f:
 bytes = f.read()
 sha256_bl = hashlib.sha256(bytes).hexdigest()

bootout.seek(0x5B6DE0)
bootout.write(aes_ctr_dec(bytes, bootloader_key, bootloader_ctr))
BL.close()
os.remove(bootloader)
#--------------设置菜单四个按钮---------
#Payload_A0000000.bin
payA0_dec = open(payloadA0, "wb")
payA0_dec.write(aes_ctr_dec(bootin[0xF3D820:0xF3D820+0x2AE220], payloadA0_key, payloadA0_ctr))
payA0_dec.seek(0x0)
payA0_2 = open(payloadA0, "rb")
payA0_2_tmp = payA0_2.read()
payA0_dec.write(aes_ctr_dec(payA0_2_tmp, fw_key, fw_ctr))
payA0_2.close()

#license key
if sdfile == "n":
    KEY1 = unhexlify("ef5d659c14077718b4ff06aa9e0400e9fb324f163f1f6600d58cc0f904138e36005cefc7462fbc90790047c7208c75b87e7500274f9b5ffe62b5c500269c9ab272ec5f94009827dcd1a243ed8700d4bdd4a747033f7900eb54d6a1256377b400ba0fc7b1f1edcc430080ebe2233896954200c6a06df1349a4d2600794a3b4657ccef3500abf54b11d8bc574a005ff7b0f8bc51eab600d143de2b98c5f893009e8a32c6076c55e700f3c43f5b27cc34fd00eaff9293f7e841d600e18f081bd7620cab00651f5bca1afca4d100479435fada06df8100591abcbe0629ba6d00f3a46320d44d40fe005a40678063c1c645002b65132a0326ac8e00118ef0e084f65a7f00888070e522a9f63e00af862436255a7f8f009c4b3009033860c700fb637b")
    payA0_dec.seek(0x22D861)
    payA0_dec.write(KEY1)
    KEY2 = unhexlify("ef5d21659c147718b4ff0600aa9e04e9fb324f16003f1f66d58cc0f90400138e365cefc7462f00bc907947c7208c7500b87e75274f9b5ffe0062b5c5269c9ab27200ec5f949827dcd1a20043ed87d4bdd4a74700033f79eb54d6a125006377b4ba0fc7b1f100edcc4380ebe2233800969542c6a06df134009a4d26794a3b465700ccef35abf54b11d800bc574a5ff7b0f8bc0051eab6d143de2b9800c5f8939e8a32c607006c55e7f3c43f5b2700cc34fdeaff9293f700e841d6e18f081bd700620cab651f5bca1a00fca4d1479435fada0006df81591abcbe060029ba6df3a46320d4004d40fe5a4067806300c1c6452b65132a030026ac8e118ef0e08400f65a7f888070e52200a9f63eaf86243625005a7f8f9c4b300903003860c7fb63aa")
    payA0_dec.seek(0x237B72)
    payA0_dec.write(KEY2)

pub_key_reboot = unhexlify("7b63fbc76038030900304b9c8f7f5a2536002486af3ef6a922e5007080887f5af684e000f08e118eac26032a0013652b45c6c163800067405afe404dd4200063a4f36dba2906be00bc1a5981df06dafa00359447d1a4fc1aca005b1f65ab0c62d71b00088fe1d641e8f7930092ffeafd34cc275b003fc4f3e7556c07c600328a9e93f8c5982b00de43d1b6ea51bcf800b0f75f4a57bcd811004bf5ab35efcc5746003b4a79264d9a34f1006da0c6429596382300e2eb8043ccedf1b100c70fbab4776325a100d654eb793f0347a700d4bdd487ed43a2d100dc2798945fec72b2009a9c26c5b562fe5f009b4f27757eb8758c0020c7477990bc2f4600c7ef5c368e1304f900c08cd5661f3f164f0032fbe9049eaa06ff00b41877149c655def")
payA0_dec.seek(0x29A4C2)
payA0_dec.write(pub_key_reboot)
payA0_dec.seek(0x0)

with open(payloadA0, 'rb') as f:
    bytes = f.read()
    sha256_patcher_1 = hashlib.sha256(bytes[0x400:0x1E3E40]).hexdigest() 
    sha256_patcher_2 = hashlib.sha256(bytes[0x1E3E40:0x1E6800]).hexdigest() 
    sha256_patcher_3 = hashlib.sha256(bytes[0x1E6800:0x1EFA60]).hexdigest() 
    sha256_patcher_4 = hashlib.sha256(bytes[0x1EFA60:0x2AE214]).hexdigest()  
payA0_dec.seek(0x10)
payA0_dec.write(unhexlify(sha256_patcher_1))
payA0_dec.seek(0x40)
payA0_dec.write(unhexlify(sha256_patcher_2))
payA0_dec.seek(0x70)
payA0_dec.write(unhexlify(sha256_patcher_3))
payA0_dec.seek(0xA0)
payA0_dec.write(unhexlify(sha256_patcher_4))
payA0_dec.close()

with open(payloadA0, 'rb') as f:
    bytes = f.read()
    sha256_header_patcher = hashlib.sha256(bytes[0x0:0x3E0]).hexdigest()  

payA0_dec = open(payloadA0_dec2, "wb")
payA0_dec.write(bytes)
payA0_dec.seek(0x3E0)
payA0_dec.write(unhexlify(sha256_header_patcher))
payA0_dec.close()

payA0_dec = open(payloadA0_dec2, "rb")
payA0 = payA0_dec.read()
payA0_dec.close()

payA0_enc = open(payloadA0_enc, "wb")
payA0_enc.write(aes_ctr_dec(payA0, fw_key, fw_ctr))
payA0_enc.close()

with open(payloadA0_enc, 'rb') as f:
    bytes = f.read()
    sha256_payA0_enc = hashlib.sha256(bytes).hexdigest()  

bootout.seek(0xF3D820)
bootout.write(aes_ctr_dec(bytes, payloadA0_key, payloadA0_ctr))
os.remove(payloadA0)
os.remove(payloadA0_enc)
os.remove(payloadA0_dec2)

#payload90000000.bin
pay90 = open(payload90, "wb")
pay90.write(aes_ctr_dec(bootin[0xC958D0:0xDBA410], payload90_key, payload90_ctr))

#sha256 payloadA0
pay90.seek(0x11F050)
pay90.write(unhexlify(sha256_payA0_enc))
pay90.close()

with open(payload90, 'rb') as f:
    bytes = f.read()
    sha256_pay90 = hashlib.sha256(bytes).hexdigest()  
sha256_pay90_xor = hexxor(KEYXOR,sha256_pay90)
bootout.seek(0xC958D0)
bootout.write(aes_ctr_dec(bytes, payload90_key, payload90_ctr))
pay90.close()
os.remove(payload90)
#----------------------------------------
#payload80000000.bin
pay81 = open(payload81, "wb")
pay81.write(aes_ctr_dec(bootin[0x201E0:0x1F6DE0], payload81_key, payload81_ctr))
#sha256 booloader
pay81.seek(0x1C9FE8)
pay81.write(unhexlify(sha256_bl))

if os.path.isfile(Request) and islicense == "y":
    pay81.seek(0x17BDA0)
    pay81.write(unhexlify("A4BD1781"))
    pay81.seek(0x8258)
    pay81.write(unhexlify(pub_key))
elif not os.path.isfile(Request) and islicense == "y":
    if os.path.isfile("fingerprint.txt"):
        f = open("fingerprint.txt", "r")
        sxos_fingerprint = f.read(32)
        f.close
    else:
        sxos_fingerprint = ("5602D40FA505523444544A4200011500") #Inaki
    fingerprint = unhexlify(sxos_fingerprint)
    pay81.seek(0x19FF14)
    pay81.write(patch_d)
    pay81.seek(0x1C6000)
    pay81.write(patch_spoof)
    pay81.seek(0x1C6100)
    pay81.write(fingerprint)

pay81.seek(0x1D2A14)
pay81.write(unhexlify(sha256_pay90_xor))
pay81.seek(0x0)

pay81.close()

with open(payload81, 'rb') as f:
    bytes = f.read()
    sha256_pay81 = hashlib.sha256(bytes).hexdigest()  

bootout.seek(0x201E0)
bootout.write(aes_ctr_dec(bytes, payload81_key, payload81_ctr))
os.remove(payload81)

#--------------设置开机动画---------
if os.path.isfile('out/splash.bin'):
 fb_in = open(fb, "wb")
 fb_in.write(aes_ctr_dec(bootin[0x1F6DE0:0x1F6DE0+0x3C0000], fb_key, fb_ctr))
 
 tmp = open('out/splash.bin', "rb")
 FB_splash = tmp.read()
 tmp.close()
 
 fb_in.seek(0x0)
 fb_in.write(FB_splash)
 fb_in.seek(0x0)

 with open(fb, 'rb') as f:
     bytes = f.read()
     sha256_fb = hashlib.sha256(bytes).hexdigest()

 bootout.seek(0x1F6DE0)
 bootout.write(aes_ctr_dec(bytes, fb_key, fb_ctr))
 fb_in.close()
 os.remove(fb)
#--------------设置开机动画End---------

#stage3 40020000.bin
stage3_in = open(stage3, "wb")
stage3_in.write(aes_ctr_dec(bootin[0x11500:0x1BB70], s3_key, s3_ctr))
if os.path.isfile('out/splash.bin'):
 stage3_in.seek(0xA5D0)
 stage3_in.write(unhexlify(sha256_fb))
stage3_in.seek(0xA620)
stage3_in.write(unhexlify(sha256_pay81))
stage3_in.seek(0x0)

with open(stage3, 'rb') as f:
    bytes = f.read()
    sha256_stage3 = hashlib.sha256(bytes).hexdigest()

bootout.seek(0x11500)
bootout.write(aes_ctr_dec(bytes, s3_key, s3_ctr))
stage3_in.close()
os.remove(stage3)
#------------------

#stage2_40008100
stage2_in = open(stage2, "wb")
stage2_in.write(aes_ctr_dec(bootin[0x100:0x110D0], s2_key, s2_ctr))

#Key Signature
key_reverse = reverse(pub_key,512)
stage2_in.seek(0x53A3)
stage2_in.write(unhexlify(key_reverse))

#stage2_in.seek(0x45C0)
#stage2_in.write(patch_s2)
stage2_in.seek(0x0)

with open(stage2, 'rb') as f:
    bytes = f.read()
    sha256_stage2 = hashlib.sha256(bytes).hexdigest()

bootout.seek(0x100)
bootout.write(aes_ctr_dec(bytes, s2_key, s2_ctr))
stage2_in.close()
os.remove(stage2)
#-------------------

#header.bin
header_m = open(header, "wb")
header_m.write(bootin[0x0:0xE0])
header_m.seek(0x10)
header_m.write(unhexlify(sha256_stage2))
header_m.seek(0x0)
header_m.close()

with open(header, 'rb') as f:
  bytes = f.read()
  sha256_header = hashlib.sha256(bytes).hexdigest()
bootout.seek(0x0)
bootout.write(bytes)
header_m.close()
os.remove(header)
#-------------------

#header.bin stage3
header_m_s3 = open(header_s3, "wb")
header_m_s3.write(bootin[0x11300:0x113E0])
header_m_s3.seek(0x20)
header_m_s3.write(unhexlify(sha256_stage3))
header_m_s3.seek(0x0)


with open(header_s3, 'rb') as f:
    bytes = f.read()
    sha256_header_sig_s3 = hashlib.sha256(bytes).hexdigest()
bootout.seek(0x11300)
bootout.write(bytes)
header_m_s3.close()
os.remove(header_s3)
#------------------

#--------------设置开机相册SXOS界面---------
rom_in = open(rommenu, "wb")

if islicense == 'y':
  rom_in.write(aes_ctr_dec(bootin[0x11EBA40:0x15c8080], fw_key, fw_ctr))
  rom_in.seek(0x126d4+0x610)
  rom_in.write(unhexlify("C3FFFF17"))
  rom_in.seek(0x124FC+0x610)
  rom_in.write(unhexlify("01248052"))
  rom_in.seek(0x125e0+0x610)
  rom_in.write(unhexlify("A30C00F00600805263C00B91"))
  
  rom_in.seek(0x13AAD0)
  rom_in.write(licenseStatus.encode()+END)

if os.path.isfile('themes/rommenu.jpeg') and isthemes:
  tmp = open('themes/rommenu.jpeg', "rb")
  GFX_rommenu = tmp.read()
  tmp.close()
  rom_in.seek(0xF9018+0x610)
  rom_in.write(GFX_rommenu)

if sdfile == "y":
    rom_in.seek(0x12A5C) # make license check valid. (0x1244c + 0x160)
    rom_in.write(NOP)
    rom_in.seek(0x14B18) # fix cheat menu
    rom_in.write(NOP)

rom_in.seek(0x0)
with open(rommenu, 'rb') as f:
    bytes = f.read()
    sha256_rommenu = hashlib.sha256(bytes[0x610:0x1AC610]).hexdigest()
rom_in.seek(0x18)
rom_in.write(unhexlify(sha256_rommenu))
rom_in.seek(0x0)
rom_in = open(rommenu, "rb")
rom_in2 = rom_in.read()
bootout.seek(0x11EBA40)
bootout.write(aes_ctr_dec(rom_in2, fw_key, fw_ctr))
rom_in.close()
os.remove(rommenu)
#--------------设置开机相册SXOS界面End---------

#--------------生成boot.dat---------
f = open(bootbin, "rb")
bootin = f.read()
bootout = open(boot, "wb")
bootout.write(bootin)
bootout.seek(0xE0)
bootout.write(unhexlify(sha256_header))
bootout.seek(0x113E0)
bootout.write(unhexlify(sha256_header_sig_s3))
f.close()

#Header Signature
tmp_header = reverse(sha256_header,64)

with open("header_sig.bin", "wb") as sig_header:
    sig_header.write(unhexlify(padding))
    sig_header.seek(0xE0)
    sig_header.write(unhexlify(tmp_header))

with open("header_sig.bin", "rb") as sig_header_tmp:
    sig_header = sig_header_tmp.read()

signature = sig_RSA(sig_header)
sig_header_reverse = reverse(signature,512)
bootout.seek(0x11200)
bootout.write(unhexlify(sig_header_reverse))
os.remove("header_sig.bin")

#Header Signature s3
tmp_header = reverse(sha256_header_sig_s3,64)
with open("header_sig.bin", "wb") as sig_header:
    sig_header.write(unhexlify(padding))
    sig_header.seek(0xE0)
    sig_header.write(unhexlify(tmp_header))

with open("header_sig.bin", "rb") as sig_header_tmp:
    sig_header = sig_header_tmp.read()

signature = sig_RSA(sig_header)
sig_header_reverse = reverse(signature,512)
bootout.seek(0x11400)
bootout.write(unhexlify(sig_header_reverse))
os.remove("header_sig.bin")
#---------------------

bootout.close()
os.remove(bootbin)
printDarkGreen("\n 成功创建boot.dat!!! \n")
#--------------写入boot.dat End---------

if islicense == "y":
  create_license()
#------------------------
dist_url = os.path.abspath(dist)
printDarkGreen("\n 生成文件路径为：" + dist_url)
# 自动打开路径
os.system('explorer ' + dist_url)
print("\n")
os.system('pause')
